/**
 * 
 */
package com.axxc.jpa.specification;

import java.io.Serializable;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.apache.commons.lang3.StringUtils;
import org.springframework.data.jpa.domain.Specification;

import com.axxc.jpa.entity.VisitLogEntity;
import com.axxc.jpa.out.Developer;
import com.axxc.jpa.out.model.VisitLog;

/**
 * @ClassName: VisitLogSpec
 * @Description: 访问日志类过滤条件对象
 * @author 熊小川
 * @date 2018年6月6日 下午10:19:13
 * @See
 */
public class VisitLogSpec extends Developer implements Serializable, Specification<VisitLogEntity> {

	private static final long serialVersionUID = 1L;

	private VisitLog visitLog;

	public VisitLogSpec(VisitLog visitLog) {
		super();
		this.visitLog = visitLog;
	}

	@Override
	public Predicate toPredicate(Root<VisitLogEntity> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
		// TODO 筛选条件
		Predicate predicate = null;
		if (visitLog != null) {
			predicate = cb.conjunction();
			if (StringUtils.isNotBlank(visitLog.getVisitHttpMethod())) {
				predicate=cb.and(predicate, cb.like(root.get("visitHttpMethod"), "%" + visitLog.getVisitHttpMethod().toUpperCase() + "%"));
			}

			if (StringUtils.isNotBlank(this.visitLog.getVisitDate())) {
				logger.info("参数date:{},未处理", visitLog.getVisitDate());
			}

		}
		return predicate;

	}

}
